#include "plotmanager.h"
#include <QGridLayout>
#include <QScrollArea>
#include <QPushButton>
#include <qwt_slider.h>
//
PlotManager::PlotManager( DataFile * file, QWidget * parent )
	: QWidget(parent), pDataFile(file)
{
	qDebug( "PlotManager::PlotManager(QWidget)" );

	QGridLayout * layout = new QGridLayout;

	QPushButton * zoomIn = new QPushButton( trUtf8("Powiększ") );
	QPushButton * zoomOut = new QPushButton( trUtf8("Pomniejsz") );
	layout->addWidget( zoomIn, 0, 0 );
	layout->addWidget( zoomOut, 0, 1 );
	layout->setColumnStretch( 2, 1 );

	QwtSlider *slider = new QwtSlider(this);
	slider->setRange(0,pDataFile->samplesCount(),1,500);
	layout->addWidget(slider, 1, 0, 1, 3 );
//		slider->setThumbLength(slider->width());
//		slider->setScalePosition(QwtSlider::BottomScale);

	QScrollArea * scrollArea = new QScrollArea;
	QWidget * scrollWidget = new QWidget;
	QVBoxLayout * vlayout = new QVBoxLayout;

	int chanCount = pDataFile->getChannels();
	for( int i = 0; i < chanCount; i++ ) {
		DataPlot * chanPlot = new DataPlot( pDataFile, QwtText( trUtf8(" Kanał nr ")+QString::number( i ) ) );
		chanPlot->setCurrentChannel( i );
		vlayout->addWidget( chanPlot );
		connect(slider,SIGNAL(valueChanged(double)),chanPlot,SLOT(panPlot(double)));
		connect(zoomIn,SIGNAL(clicked()),chanPlot,SLOT(zoomIn()));
		connect(zoomOut,SIGNAL(clicked()),chanPlot,SLOT(zoomOut()));
		chanPlots << chanPlot;
	}
	scrollWidget->setLayout(vlayout);
	scrollArea->setWidget(scrollWidget);
	scrollArea->setWidgetResizable( true );
	layout->addWidget(scrollArea, 2, 0, 1, 3 );
	// TODO: insert spacer at end

	setLayout( layout );
}
//
PlotManager::~PlotManager()
{
	qDebug( "PlotManager::~PlotManager()" );
}
//
